<table class="form-table-without-line">
    <tr class="client_title">
        <th>站点名称</th>
        <td>
            <input type="text" id="name" placeholder="输入站点名称" class="am-form-field" required/>
            <button type="button" class="btn-name">保存</button>
        </td>
    </tr>

    <tr class="client_log_big">
        <th>站点LOGO</th>
        <td>
            <img src="../public/all/images/upload.jpg" class="logo-big" width="120px;"/>
            <input type="file" class="logo-big" data-url="/tephra/ctrl-http/upload" multiple>
        </td>
    </tr>

    <!--
    <tr class="client_log_small">
        <th>站点LOGO（小）</th>
        <td>
            <img src="../public/all/images/upload.jpg" class="logo-small" width="80px;"/>
            <input type="file" class="logo-small" data-url="/tephra/ctrl-http/upload" multiple>
        </td>
    </tr> -->

    <tr class="client_maintain">
        <th>站点状态</th>
        <td>
            <div style="margin-bottom: 8px;">
                <label class="am-checkbox">
                    <input type="checkbox" value="" data-am-ucheck checked> 开启
                </label>
                <label class="am-radio-inline red">
                    关闭网站不能充值、不能提现、不能下注
                </label>
            </div>
            <textarea id="mainten_content" minlength="10" maxlength="500" rows="5"
                placeholder="请输入维护公告内容"></textarea>
            <button type="button" class="btn-mainten">保存</button>
        </td>
    </tr>

    <tr class="client_bet_enable">
        <th>是否允许下注</th>
        <td>
            <div class="input">
                <label class="am-checkbox">
                    <input type="checkbox" value="" data-am-ucheck checked> 开启
                </label>
            </div>
            <div class="clue" style="font-size:12px; padding-top: 5px;">
                游戏管理可以针对单个游戏控制，<a href="admin.html?n1=游戏管理&n2=游戏设定">去游戏管理>></a>
            </div>
            <button type="button" class="btn-bet">保存</button>
        </td>
    </tr>

    <tr class="client_charge_enable">
        <th>是否开启充值</th>
        <td>
            <div class="input">
                <label class="am-checkbox">
                    <input type="checkbox" value="" data-am-ucheck checked> 开启
                </label>
            </div>
            <button type="button" class="btn-charge">保存</button>
        </td>
    </tr>

    <tr class="client_new_user">
        <th>新会员注册赠送</th>
        <td>
            <input type="number" id="zengsong" placeholder="请输入金额，单位：元" class="am-form-field" required/>
            <button type="button" class="btn-zengsong">保存</button>
        </td>
    </tr>

    <tr class="client_dw">
        <th>打水倍数</th>
        <td>
            <input type="number" id="bet-req" placeholder="请输入充值的几倍流水才能提款" class="am-form-field" required/>
            <button type="button" class="btn-bet-req">保存</button>
        </td>
    </tr>
    
    <tr class="login_timeout">
        <th>登录超时</th>
        <td>
            <input type="number" id="login-timeout" placeholder="单位：分钟" class="am-form-field" required/>
            <div class="clue" style="font-size:12px; padding-top: 5px;">
                单位：分钟。关闭浏览器后多久，认为登录超时。
            </div>
            <button type="button" class="btn-login-timeout">保存</button>
        </td>
    </tr>

    <tr class="login_lock">
        <th>登录锁定</th>
        <td>
            <input type="number" id="login-lock" placeholder="单位：分钟" class="am-form-field" required/>
            <div class="clue" style="font-size:12px; padding-top: 5px;">
                账号连续输入几次错误密码后，将被锁定10分钟无法登录。
            </div>
            <button type="button" class="btn-login-lock">保存</button>
        </td>
    </tr>

    <tr class="register-lock">
        <th>注册限制</th>
        <td>
            <input type="number" id="register-lock" placeholder="单位：分钟" class="am-form-field" required/>
            <div class="clue" style="font-size:12px; padding-top: 5px;">
                同一个IP，在指定时间（单位：分钟）内只能注册一个账号！
            </div>
            <button type="button" class="btn-register-lock">保存</button>
        </td>
    </tr>

    <tr class="deposit-interval">
        <th>充值提交间隔时间</th>
        <td>
            <input type="number" id="deposit-interval" placeholder="单位：秒" class="am-form-field" required/>
            <div class="clue" style="font-size:12px; padding-top: 5px;">
                0表示不限制，单位：秒
            </div>
            <button type="button" class="btn-deposit-interval">保存</button>
        </td>
    </tr>

    <tr class="deposit-withdraw">
        <th>提现提交间隔时间</th>
        <td>
            <input type="number" id="withdraw-interval" placeholder="单位：秒" class="am-form-field" required/>
            <div class="clue" style="font-size:12px; padding-top: 5px;">
                0表示不限制，单位：秒
            </div>
            <button type="button" class="btn-deposit-withdraw">保存</button>
        </td>
    </tr>

    <tr class="same-name">
        <th>是否允许同名注册</th>
        <td>
            <div class="input">
                <label class="am-checkbox">
                    <input type="checkbox" value="" data-am-ucheck checked> 允许
                </label>
            </div>
            <button type="button" class="btn-same-name">保存</button>
        </td>
    </tr>

    <tr class="bet-max">
        <th>注单最高派彩</th>
        <td>
            <div class="input">
                <input type="number" id="bet-max" placeholder="单位：元" class="am-form-field" required/>
            </div>
            <button type="button" class="btn-bet-max">保存</button>
        </td>
    </tr>
</table>

<style type="text/css">
    .form-table-without-line .logo-small, .form-table-without-line .logo-big {
        border: 1px solid #333;
    }
</style>

<script>
    // 权限控制
    var m = {
        "/client/title": "client_title",
        "/client/log_big": "client_log_big",
        "/client/log_small": "client_log_small",
        "/client/maintain": "client_maintain",
        "/client/bet_enable" : "client_bet_enable",
        "/client/charge_enable": "client_charge_enable",
        "/client/new_user": "client_new_user",
        "/client/dw": "client_dw",
    };
    Util.applyRights(m);

    $("input[type='checkbox']").uCheck();

    // 网站标题
    Classify.query("settings", "title", false, "中盈", function(v) {
        $("#name").val(v);
    });
    $(".btn-name").click(function() {
        var s = $("#name").val().trim();
        if (s == '') return;
        Classify.save("settings", "title", s, function(r) {
            alert2("修改站点名称完成。");
        });
    });
   
    // 站点状态
    function set_close(isClose, content) {
        $(".client_maintain input[type='checkbox']").uCheck(isClose ? 'uncheck' : 'check');
        $("#mainten_content").val(content);
    }
    Classify.queryExt("settings", "mainten", true, {}, function(v) {
        set_close(v.close, v.content || '');
    });
    $(".btn-mainten").click(function() {
        var isClose = !$(".client_maintain input[type='checkbox']")[0].checked;
        var s = $("#mainten_content").val().trim();
        Classify.saveExt("settings", "mainten", {
            close: isClose ? 1 : 0,
            content: s,
        }, function() {
            alert2("修改站点状态完成。");
        });
    });

    // 充值状态
    function set_charge_close(isClose) {
        $(".client_charge_enable input[type='checkbox']").uCheck('uncheck');
    }
    Classify.query("settings", "charge_enable", false, "1", function(v) {
        if (!v)
            set_charge_close(v);
    });
    $(".btn-charge").click(function() {
        var isClose = !$(".client_charge_enable input[type='checkbox']")[0].checked;
        Classify.save("settings", "charge_enable", isClose ? "0" : "1", function() {
            alert2("修改充值状态完成。");
        });
    });

    // 下注状态
    function set_bet_close(isClose) {
        $(".client_bet_enable input[type='checkbox']").uCheck('uncheck');
    }
    Classify.query("settings", "bet_enable", false, "1", function(v) {
        if (v == '0')
            set_bet_close(v);
    });
    $(".btn-bet").click(function() {
        var isClose = !$(".client_bet_enable input[type='checkbox']")[0].checked;
        Classify.save("settings", "bet_enable", isClose ? "0" : "1", function() {
            alert2("修改下注状态完成。");
        });
    });

    // 充值水流要求
    Classify.query("eddy.account.dw", "rate", false, 1, function(v) {
        $("#bet-req").val(v);
    });
    $(".btn-bet-req").click(function() {
        startLoading();
        Classify.save("eddy.account.dw", "rate", $("#bet-req").val(), function() {
            stopLoading();
            alert2("修改成功。");
        });
    });

    // LOGO（大）
    Classify.queryExt("settings", "logo-big", false, "", function(v) {
        if (v) {
            var url = context.config.url.replace(":9090", "");
            $("img.logo-big").attr("src", url + v);
        }
    });
    $("input.logo-big").change(function() {
        var data = new FormData();
        var file = $("input.logo-big")[0].files[0];
        if (file.size > 100 * 1024) {
            alert2("LOGO大小必须小于100K！", true);
            return;
        }
        data.append("eddy.message.image", $("input.logo-big")[0].files[0]);
        
        startLoading();
        CMD.upload(data, null, function(r) {
            var url = context.config.url.replace(":9090", "");
            $("img.logo-big").attr("src", url + r);
            Classify.saveExt("settings", "logo-big", r, function() {
                stopLoading();
                alert2("保存成功！");
            });
        });
    });

    /*
    // LOGO（小）
    Classify.queryExt("settings", "logo-small", false, "", function(v) {
        if (v) {
            $("img.logo-small").attr("src", context.config.url + v);
        }
    });
    $("input.logo-small").change(function() {
        var data = new FormData();
        var file = $("input.logo-small")[0].files[0];
        if (file.size > 80 * 1024) {
            alert2("LOGO大小必须小于80K！", true);
            return;
        }
        data.append("eddy.message.image", $("input.logo-small")[0].files[0]);
        
        startLoading();
        CMD.upload(data, null, function(r) {
            $("img.logo-small").attr("src", r);
            Classify.saveExt("settings", "logo-small", r, function() {
                stopLoading();
                alert2("保存成功！");
            });
        });
    });
    */

    // 首次注册用户赠送金额
    Classify.query("account.reward", "first-register", false, 0, function(v) {
        $("#zengsong").val(v/100);
    });
    $(".btn-zengsong").click(function() {
        var s = $("#zengsong").val().trim();
        if (s == '') return;
        if (parseInt(s) < 0) {
            alert2("金额不能为负数！", true);
            return;
        }
        Classify.save("account.reward", "first-register", s * 100, function(r) {
            alert2("修改完成！");
        });
    });

    // 登录锁定
    Classify.query("eddy.user.pass", "max-failure", false, 5, function(r) {
        $("#login-lock").val(r);
    });
    $(".btn-login-lock").click(function() {
        var s = $("#login-lock").val();
        if (s == '' || parseInt(s) <= 0) {
            alert2("次数不对！", true);
            return;
        }
        startLoading();
        Classify.save("eddy.user.pass", "max-failure", s, function() {
            stopLoading();
            alert2("保存成功！");
        });
    });

    // sid超时
    Classify.query("eddy.user.online", "timeout", false, 30, function(r) {
        $("#login-timeout").val(r);
    });
    $(".btn-login-timeout").click(function() {
        var s = $("#login-timeout").val();
        startLoading();
        Classify.save("eddy.user.online", "timeout", s, function() {
            stopLoading();
            alert2("保存成功！");
        });
    });

    // 注册限定
    Classify.query("eddy.user.sign-up.ip", "max-minute", false, 30, function(r) {
        $("#register-lock").val(r);
    });
    $(".btn-register-lock").click(function() {
        var s = $("#register-lock").val();
        if (s == '') {
            alert2("时间间隔不对！", true);
            return;
        }
        startLoading();
        Classify.save("eddy.user.sign-up.ip", "max-minute", s, function() {
            stopLoading();
            alert2("保存成功！");
        });
    });

    // 同名注册
    function set_same_name_close(isClose) {
        $(".same-name input[type='checkbox']").uCheck('uncheck');
    }
    Classify.query("eddy.user", "same-name", false, "", function(v) {
        if (v == 'false')
            set_same_name_close(v);
    });
    $(".btn-same-name").click(function() {
        var isClose = !$(".same-name input[type='checkbox']")[0].checked;
        Classify.save("eddy.user", "same-name", isClose ? "0" : "1", function() {
            alert2("修改完成。");
        });
    });

    // 充值、提现时间间隔
    Classify.query("eddy.account.create-interval", "deposit", false, 0, function(r) {
        $("#deposit-interval").val(r);
    });
    $(".btn-deposit-interval").click(function() {
        startLoading();
        Classify.save("eddy.account.create-interval", "deposit", $("#deposit-interval").val(), function() {
            stopLoading();
            alert2("保存成功！");
        });
    });
    Classify.query("eddy.account.create-interval", "withdraw", false, 0, function(r) {
        $("#withdraw-interval").val(r);
    });
    $(".btn-deposit-withdraw").click(function() {
        startLoading();
        Classify.save("eddy.account.create-interval", "withdraw", $("#withdraw-interval").val(), function() {
            stopLoading();
            alert2("保存成功！");
        });
    });

    // 最高派彩
    Classify.query("eddy.bet", "max-win", false, 0, function(r) {
        $("#bet-max").val(r/100);
    });
    $(".btn-bet-max").click(function() {
        var s = $("#bet-max").val().trim();
        startLoading();
        if (s) s = s * 100 + "";
        Classify.save("eddy.bet", "max-win", s, function() {
            stopLoading();
            alert2("保存成功！");
        });
    });

    /*
    var aaa = ["zypk10", "zyssc", "zykl10"];
    for (var i in aaa) {
        Classify.save("lottery.type.interval", aaa[i], 75);
        Classify.save("lottery.type.end", aaa[i], 15);
    }
    aaa = ["zykl8", "zy115", "zyk3"];
    for (var i in aaa) {
        Classify.save("lottery.type.interval", aaa[i], 300);
        Classify.save("lottery.type.end", aaa[i], 60);
    }
    */
</script>
